import { Message , Loading} from 'element-ui'

import Vue from 'vue';

const showMessage = Symbol('showMessage')
const standyMessageList = new Array()
class OnlyMessage {
    success (options, single = true) {
        this[showMessage]('success', options, single)
    }
 
    warning (options, single = true) {
        this[showMessage]('warning', options, single)
    }
 
    info (options, single = true) {
        this[showMessage]('info', options, single)
    }
 
    error (options, single = true) {

        this[showMessage]('error', options, single)
    }

    popMessage(options){
        standyMessageList.shift();
    }

    existMessage(options){
        var exist = false;
        standyMessageList.forEach(element => {
            
            if(element['message'] === options['message']){
                exist = true;
             return;
            }
        });
        return exist;
    }
    
 
    [showMessage] (type, content, single) {
        var options = {
            message: content,//提示的信息
            type:type,　　//类型是成功
            duration:3000,　　//显示时间, 毫秒。设为 0 则不会自动关闭
            onClose:()=>{
            　　//此处写提示关闭后需要执行的函数
                this.popMessage(options);
            }
        }
        if (single) {
            if(this.existMessage(options)){
                return;
            }
            Message[type](options);
            standyMessageList.push(options);
        } else {
            Message[type](options)
        }
    }
}


 
export default new OnlyMessage()